//引入vue
import Vue from "vue";

//引入路由包
import VueRouter from "vue-router";

//安装插件到vue上
Vue.use(VueRouter);

// 引入要跳转的组件
// Home-首页
import Home from "../views/Home/Home.vue"
import HomeHot from "../views/Home/HomeHot.vue"
import HomeTv from "../views/Home/HomeTv.vue"
import HomeMovie from "../views/Home/HomeMovie.vue"

// shortvideo页面
import Svideo from "../views/Shortvideo/Svideo.vue"
import DetailsVideo from "../views/Home/components/DetailsVideo.vue"
// import DetailsWxq from "../views/wxq/components/DetailsWxq.vue"

// VIP页
import Vip from "../views/Vip/Vip.vue"
import Fls from "../views/Vip/Fls.vue"
import Zx from "../views/Vip/Zx.vue"
import Dy from "../views/Vip/Dy.vue"
import Kaitong from "../views/Vip/Kaitong.vue"



// Community-社区页
import Shequ from "../views/Community/Shequ.vue"
import Guangchang from "../views/Community/Guangchang.vue"
import Jiewu from "../views/Community/Jiewu.vue"
import Choujiang from "../views/Community/Choujiang.vue"
import News from "../views/Community/News.vue"
import Newsnav from "../views/Community/components/Newsnav.vue";
import Fans from "../views/Community/components/Fans.vue";
import Xiangqin from "../views/Community/components/Xiangqin.vue";


//my-我的页面
import My from "../views/My/My.vue"
import Login from "../views/My/Login.vue"
import Register from "../views/My/Register.vue"
import Self from "../views/My/Self.vue"
import Shipingshoucang from "../views/My/Shipingshoucang.vue"
import Manhuashoucang from "../views/My/Manhuashoucang.vue"
import Jilu from "../views/My/Jilu.vue"
import Collection from "../views/My/Collection.vue"
import Order from "../views/My/Order.vue"

// 路由跳转配置
let routes = [
    // home

    {
        path: '/',
        component: Home
    },
    {
        path: '/home',
        component: Home
    },
    {
        path: '/HomeHot',
        component: HomeHot
    },
    {
        path: '/HomeTv',
        component: HomeTv
    },
    {
        path: '/HomeMovie',
        component: HomeMovie
    },
    {
        path: '/Dy',
        component: Dy
    },

    // 详情跳转路由

    {
        path: '/DetailsVideo',
        name: 'DetailsVideo',
        component: DetailsVideo
    },


    // DIY短视屏页面
    {
        path: '/Svideo',
        component: Svideo
    },
    //vip
    {
        path: '/Vip',
        component: Vip
    },
    {
        path: '/Fls',
        component: Fls
    },
    {
        path: '/Zx',
        component: Zx
    },

    {
        path: '/Dy',
        component: Dy
    },
    {
        path: '/Kaitong',
        component: Kaitong
    },
    // {
    //     path: '/bofang-1/:movieid',
    //     component: Bf
    // },
    //shequ
    {
        path: '/Shequ',
        component: Shequ
    },
    {
        path: '/Guangchang',
        component: Guangchang
    },
    {
        path: '/Jiewu',
        component: Jiewu
    },
    {
        path: '/Choujiang',
        component: Choujiang
    },
    {
        path: '/News',
        component: News
    },
    {
        path: "/Newsnav",
        component: Newsnav
    },
    {
        path: "/Fans",
        component: Fans
    },
    {
        path: "/Xiangqin",
        component: Xiangqin
    },
    //MY
    {
        path: '/My',
        component: My
    },
    {
        path: '/Login',
        component: Login
    },
    {
        path: '/Register',
        component: Register
    },
    {
        path: '/Self',
        component: Self
    },
    {
        path: '/Jilu',
        component: Jilu
    },
    {
        path: '/Order',
        component: Order
    },


    {
        path: '/Collection',
        component: Collection,
        children: [{
            path: '',
            component: Shipingshoucang
        },
        {
            path: 'Shipingshoucang',
            component: Shipingshoucang
        },
        {
            path: 'Manhuashoucang',
            component: Manhuashoucang
        },
        ]
    },

    // 设置路由重定向
    // {
    //     path: "/",
    //     redirect: "/home"
    // },


    // 一定要在所有配置规则的最下面
    {
        path: '*',
        name: 'no',
        component: () => import('../views/no.vue')
    },

]

// 2、创建vue Router路由对象
let router = new VueRouter({
    // mode: "history",
    routes,
})

// //全局路由守卫
router.beforeEach((to, from, next) => {
    // console.log("路由全局", "前置守卫")
    //to:想去哪
    //from:来自哪
    //next:下一步去哪(守卫的逻辑完成后,决定了去的地方)
    // console.log("to", to);
    // console.log("from", from);
    //守社区的页
    if (to.path == "/Shequ") {
        //是否登录
        if (localStorage.getItem("username")) {
            next(true);
        } else {
            next("/Login");
        }
    }
    next(true);
});

// 3、导出路由实例，让他去控制vue根
export default router;